package com.jy.adscm.hospital.service.impl;

import com.baomidou.mybatisplus.mapper.Wrapper;
import com.jy.adscm.bean.system.JyUser;
import com.jy.adscm.dealer.bean.Dealer;
import com.jy.adscm.dealer.mapper.DealerMapper;
import com.jy.adscm.hospital.bean.JyHospitalIntention;
import com.jy.adscm.hospital.bean.JyHospitalRemarks;
import com.jy.adscm.hospital.mapper.JyHospitalIntentionMapper;
import com.jy.adscm.hospital.service.JyHospitalIntentionService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.jy.adscm.system.mapper.mysql.JyUserMapper;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 意向信息 服务实现类
 * </p>
 *
 * @author yyy
 * @since 2019-01-16
 */
@Service
public class JyHospitalIntentionServiceImpl extends ServiceImpl<JyHospitalIntentionMapper, JyHospitalIntention> implements JyHospitalIntentionService {
    private Logger logger = Logger.getLogger(getClass());

    @Autowired
    JyUserMapper jyUserMapper;

    @Autowired
    DealerMapper dealerMapper;

    @Override
    public List<JyHospitalIntention> selectList(Wrapper<JyHospitalIntention> wrapper) {

        logger.info("查询医院意向信息...");

        List<JyHospitalIntention> jyHospitalIntentions = super.selectList(wrapper);

        if (jyHospitalIntentions != null && jyHospitalIntentions.size()>0){
            for (JyHospitalIntention jyHospitalIntention : jyHospitalIntentions) {
                Integer inputUserId = jyHospitalIntention.getInputUserId();
                if (inputUserId != null){
                    JyUser user = jyUserMapper.selectById(inputUserId);
                    if (user != null){
                        jyHospitalIntention.setInputUserName(user.getName());
                    }
                }

                Integer inputUnit = jyHospitalIntention.getInputUnit();
                if (inputUnit == 0){
                    jyHospitalIntention.setInputUnitDesc("生产厂商");
                }else {
                    Dealer dealer = dealerMapper.selectById(inputUnit);
                    if (dealer != null){
                        jyHospitalIntention.setInputUnitDesc(dealer.getName());
                    }
                }
            }
        }

        return jyHospitalIntentions;
    }
}
